package org.nci.platform.workflow.controller;


import gh.priv.general.common.vo.PageResult;
import gh.priv.general.common.vo.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.nci.platform.workflow.dto.SysExpressionPageQuery;
import org.nci.platform.workflow.dto.SysExpressionQuery;
import org.nci.platform.workflow.entity.SysExpression;
import org.nci.platform.workflow.service.ISysExpressionService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 流程达式Controller
 *
 * @author ruoyi
 * @date 2022-12-12
 */
@Tag(name = "流程达式")
@RestController
@RequestMapping("/flowable/expression")
public class SysExpressionController
{
    @Resource
    private ISysExpressionService sysExpressionService;

    /**
     * 查询流程达式列表
     */
    @Operation(summary = "查询流程达式列表")
    @PostMapping("/page")
    public Result<PageResult<SysExpression>> page(@RequestBody SysExpressionPageQuery query)
    {
        PageResult<SysExpression> pageResult = sysExpressionService.page(query);
        return Result.success(pageResult);
    }

    /**
     * 导出流程达式列表
     */
    @Operation(summary = "导出流程达式列表")
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestBody SysExpressionQuery query)
    {
        sysExpressionService.export(response,query);
    }

    /**
     * 获取流程达式详细信息
     */
    @Operation(summary = "获取流程达式详细信息")
    @GetMapping(value = "/{id}")
    public Result<SysExpression> getInfo(@PathVariable("id") Long id)
    {
        return Result.success(sysExpressionService.getById(id));
    }

    /**
     * 新增流程达式
     */
    @Operation(summary = "新增流程达式")
    @PostMapping
    public Result<Boolean> add(@RequestBody SysExpression sysExpression)
    {
        sysExpressionService.save(sysExpression);
        return Result.success();
    }

    /**
     * 修改流程达式
     */
    @Operation(summary = "修改流程达式")
    @PutMapping
    public Result<Boolean> edit(@RequestBody SysExpression sysExpression)
    {
        sysExpressionService.updateById(sysExpression);
        return Result.success();
    }

    /**
     * 删除流程达式
     */
    @Operation(summary = "删除流程达式")
	@DeleteMapping("/{ids}")
    public Result<Boolean> remove(@PathVariable List<Long> ids)
    {
        sysExpressionService.removeByIds(ids);
        return Result.success();
    }

    @Operation(summary = "指定流程达式列表")
    @PostMapping("/list")
    public Result<List<SysExpression>> expList(@RequestBody SysExpressionQuery query) {
        List<SysExpression> list = sysExpressionService.list(query);
        return Result.success(list);
    }
}
